﻿//iterate through each textboxes and add keyup
//handler to trigger sum event
$(document).ready(function () {
    $(".form-control").each(function () {
        $(this).keyup(function () {
            calculateSum();
        });
    });
});

function calculateSum() {
    var sum = 0;
    //each textbox and add the values
    $(".form-control").each(function () {
        if (!isNaN(this.value) && this.value.length != 0)
            sum += parseFloat(this.value);
    });

    $("#sum").html(sum.toFixed(0));

    if (sum > 2700) setState(true);
    else setState(false);
}

function setState(state) {
    if (state) {
        document.getElementById("sum").style.color = '#ff0000';
        document.getElementById("sum").style.fontWeight = 'bold';
        document.getElementById("warn3k").style.visibility = 'visible';
        document.getElementById("warn3k").style.height = '';
        document.getElementById("warn3k").style.opacity = '1';
        document.getElementById("MainContent_done").disabled = true;
    } else {
        document.getElementById("sum").style.color = '';
        document.getElementById("sum").style.fontWeight = '';
        document.getElementById("warn3k").style.visibility = 'hidden';
        document.getElementById("warn3k").style.height = '';
        document.getElementById("warn3k").style.opacity = '0';
        document.getElementById("MainContent_done").disabled = false;
    } 
}